package com.ruoyi.quartz.service.impl;

import com.alibaba.fastjson.JSON;
import com.ruoyi.quartz.mapper.CornLogMapper;
import com.ruoyi.quartz.mapper.TaskMapper;
import com.ruoyi.quartz.service.ICornLogService;
import com.ruoyi.quartz.service.ITaskService;
import com.ruoyi.system.domain.DTO.CargoInfoDTO;
import com.ruoyi.system.domain.vo.CornLog;
import com.ruoyi.system.domain.vo.OrderJobVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class TaskServiceImpl implements ITaskService {


    @Autowired
    private TaskMapper taskMapper;



    @Override
    public List<OrderJobVo> list(OrderJobVo orderJobVo) {

        List<OrderJobVo> orderJobVoList = taskMapper.list(orderJobVo);
        if(orderJobVoList != null && !orderJobVoList.isEmpty() && orderJobVoList.size() > 0){
            for (OrderJobVo forOrderJobVo:orderJobVoList) {
                if("冷藏冷箱".equals(forOrderJobVo.getProductType())){
                    if(forOrderJobVo.getCargoInfo()!=null && !"".equals(forOrderJobVo.getCargoInfo())){
                        CargoInfoDTO cargoInfoDTO = JSON.parseObject(forOrderJobVo.getCargoInfo(), CargoInfoDTO.class);
                        if(cargoInfoDTO!=null){
                            forOrderJobVo.setReeferTemperatureValue(cargoInfoDTO.getReeferTemperatureValue()+cargoInfoDTO.getReeferTemperatureType());
                            forOrderJobVo.setReeferVentilationValue(cargoInfoDTO.getReeferVentilationValue()+cargoInfoDTO.getReeferVentilationType());
                            forOrderJobVo.setReeferGenSetType(cargoInfoDTO.getReeferGenSetType());
                            forOrderJobVo.setReeferHumidityValue(cargoInfoDTO.getReeferHumidityValue().toString());
                        }else{
                            forOrderJobVo.setReeferTemperatureValue("-");
                            forOrderJobVo.setReeferVentilationValue("-");
                            forOrderJobVo.setReeferGenSetType("-");
                            forOrderJobVo.setReeferHumidityValue("-");
                        }
                    }else{
                        forOrderJobVo.setReeferTemperatureValue("-");
                        forOrderJobVo.setReeferVentilationValue("-");
                        forOrderJobVo.setReeferGenSetType("-");
                        forOrderJobVo.setReeferHumidityValue("-");
                    }
                }else{
                    forOrderJobVo.setReeferTemperatureValue("-");
                    forOrderJobVo.setReeferVentilationValue("-");
                    forOrderJobVo.setReeferGenSetType("-");
                    forOrderJobVo.setReeferHumidityValue("-");
                }
            }
        }
        return orderJobVoList;
    }
}
